<?php

namespace Domain\Task;

use Domain\User\User;
use Domain\Task\TaskListRepository;
use Domain\Task\TaskRepository;

class TaskListService {

    public function listAllLists(User $oUser) {
        $oRepository = new TaskListRepository();
        return $oRepository->findByUserID($oUser->getID());
    }

    public function submitList(ListTO $oList) {
        $oRepository = new TaskListRepository();
        return $oRepository->Insert($oList);
    }

    public function openList(User $oUser, $iListID) {
        $oTaskListRepository = new TaskListRepository();
        $oTaskList = $oTaskListRepository->Find($oUser->getID(), $iListID);

        $oTaskRepository = new TaskRepository();
        $aTasks = $oTaskRepository->findByListID($oTaskList->getID());

        foreach($aTasks as $oTask) {
            $oTaskList->addTask($oTask);
        }
        return $oTaskList;
    }

    public function changeList(ListTO $oList) {
        $oRepository = new TaskListRepository();
        return $oRepository->Update($oList);
    }

    public function removeList(User $oUser, $iListID) {
        $oRepository = new TaskListRepository();
        return $oRepository->deleteListByUserID($oUser->getID(), $iListID);
    }

}

?>
